package com.chiffoyqc.task;

import com.chiffoyqc.config.ComputeConfig;
import com.chiffoyqc.dao.DBWireLess.CF_GsmRevDao;
import com.chiffoyqc.dao.DBWireLess.CF_UserInfDao_wireLess;
import com.chiffoyqc.model.AlarmInfo;
import com.chiffoyqc.model.DBWireLess.CF_GsmRev;
import com.chiffoyqc.model.DBWireLess.CF_UserInf_wireLess;
import com.chiffoyqc.utils.ApplicationContextUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * Created by Administrator on 2018/7/23.
 */
public class ConnectionExeception_TaskItem implements Callable<List<AlarmInfo>> {
    private List<CF_UserInf_wireLess> userInfs;
    private CF_GsmRevDao gsmRevDao;
    private Date now = new Date();
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public ConnectionExeception_TaskItem(List<CF_UserInf_wireLess> userInfs) {
        this.userInfs = userInfs;
        this.gsmRevDao = ApplicationContextUtil.getBean(CF_GsmRevDao.class);
    }

    @Override
    public List<AlarmInfo> call() throws Exception {
        int count = 0;
        AlarmInfo alarmInfo;
        CF_GsmRev gsmRev;
        List<AlarmInfo> alarmInfos = new LinkedList<>();
        String alarmTime = simpleDateFormat.format(now);
        for(CF_UserInf_wireLess userInf : userInfs){
            gsmRev = gsmRevDao.selectLast(userInf.getGasUserNo());
            if(gsmRev != null){
                if((now.getTime() - gsmRev.getSedRevTime().getTime()) > ComputeConfig.connectionExecption_timeOut){
                    alarmInfo = new AlarmInfo();
                    alarmInfo.setMeterId(userInf.getGasUserNo());
                    alarmInfo.setMeterNo(userInf.getMeterNo());
                    alarmInfo.setAlarmTime(alarmTime);
                    alarmInfo.setAlarmType("1001");
                    alarmInfo.setFactoryCode(userInf.getFactoryCode());

                    alarmInfos.add(alarmInfo);
                }
            }

        }

        return alarmInfos;
    }
}
